import 'dart:developer';

import 'package:im_base/public/ext/im_base_controller.dart';
import 'package:tencent_im_sdk_plugin/models/v2_tim_conversation.dart';

class EndInquiryLogic extends IMBaseController {
  var conversationList = List<V2TimConversation?>.empty();

  void updateList(List<V2TimConversation?> list) {
    conversationList = list;
    sortConversation();
  }

  ///根据时间进行会话排序
  Future<void> sortConversation() async {
    conversationList.removeWhere((element) {
      return element?.userID == "admin" || element?.lastMessage == null;
    });
    conversationList.sort((left, right) => (right?.lastMessage?.timestamp ?? 0)
        .compareTo(left?.lastMessage?.timestamp ?? 0));
    update(['list']);
  }
}
